﻿using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AppFx.BizTalk.Diagnostics
{
    public class LogFactory
    {
        private static bool _log4netConfigLoaded = false;

        /// <summary>
        /// Gets a logger for the type
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static ILog GetLogger(Type type)
        {
            if (_log4netConfigLoaded == false)
            {
                log4net.Config.XmlConfigurator.Configure();
                _log4netConfigLoaded = true;
            }

            return LogManager.GetLogger(type);     
        }

        /// <summary>
        /// Gets an ILog configured for the central logging system for audit events
        /// </summary>
        /// <returns></returns>
        public static ILog GetAuditLogger()
        {
            const string LoggerName = "CentralLoggingSystem";        

            if (_log4netConfigLoaded == false)
            {
                log4net.Config.XmlConfigurator.Configure();
                _log4netConfigLoaded = true;
            }

            return LogManager.GetLogger(LoggerName); 
        }
    }
}
